package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询所有的频道
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult findAll() {
        return wmChannelService.findAll();
    }


    /**
     * 列表查询
     */
    @PostMapping("/list")
    public ResponseResult findPage(@RequestBody WmChannelDto dto) {
        return wmChannelService.findPage(dto);
    }


    /**
     * 保存频道数据
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel) {
        return wmChannelService.saveWmChannel(wmChannel);
    }

    /**
     * 修改频道数据
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel) {
        return wmChannelService.updateWmChannel(wmChannel);
    }

    /**
     * 根据id删除频道
     */
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return wmChannelService.deleteById(id);
    }

}
